//
//  ForgetPassWordController.m
//  YIJU2.0HD
//
//  Created by 张金国 on 16/5/19.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "ForgetPassWordController.h"
#import "Masonry.h"

@interface ForgetPassWordController ()

@property (nonatomic ,strong)UILabel            *navLabel;

@property (nonatomic ,strong)UIButton           *cancleButton;

@property (nonatomic ,strong)UIButton           *confirmButton;

@property (nonatomic ,strong)UIButton           *keyWordButton;


@end

@implementation ForgetPassWordController

#pragma mark - Life Circle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:0.929 green:0.933 blue:0.961 alpha:1.000];
    [self layoutUI];
}

#pragma mark - private
- (void)layoutUI {
    
    [self.navLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(20);
        make.left.right.equalTo(self.view);
        make.height.equalTo(@60);
    }];
    
    [self.cancleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.navLabel.mas_centerY);
        make.right.equalTo(self.navLabel.mas_right).offset(-20);
        make.width.equalTo(@73);
        make.height.equalTo(40);
    }];
    
    UIView *barView = [[UIView alloc]init];
    barView.backgroundColor = [UIColor randomColor];
    [self.view addSubview:barView];
    [barView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.navLabel.mas_bottom);
        make.left.equalTo(self.view.mas_left).offset(120);
        make.right.equalTo(self.view.mas_right).offset(-120);
        make.height.equalTo(self.navLabel.mas_height).multipliedBy(1.2);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = @"重新设置";
    titleLabel.font = [UIFont systemFontOfSize:25];
    [barView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(barView.mas_centerY);
        make.left.equalTo(barView.mas_left).offset(40);
    }];
    
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(barView.mas_bottom).offset(2);
        make.left.right.equalTo(barView);
        make.height.equalTo(@2);
    }];
    NSArray *nameArray = @[@"手机号:",@"验证码:",@"新密码:",@"确认新密码:"];
    UILabel *lastLabel = nil;
    for (int i = 0; i < 4; i++) {
        UITextField *textField = [[UITextField alloc]init];
        [self.view addSubview:textField];
        textField.layer.masksToBounds = YES;
        textField.layer.cornerRadius = 5.0f;
        textField.backgroundColor = [UIColor whiteColor];
        UILabel *label = [[UILabel alloc]init];
        label.textAlignment = NSTextAlignmentRight;
        label.font = [UIFont systemFontOfSize:23];
        [self.view addSubview:label];
        label.text = nameArray[i];
        if (lastLabel == nil) {
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(lineView.bottom).offset(40);
                make.left.equalTo(lineView.mas_left).offset(100);
                make.width.equalTo(@140);
                make.height.equalTo(@40);
            }];
        }else {
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(lastLabel.bottom).offset(40);
                make.left.equalTo(lineView.mas_left).offset(100);
                make.width.equalTo(@140);
                make.height.equalTo(@40);
            }];
        }
        lastLabel = label;
        
        [textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(label.mas_top);
            make.left.equalTo(label.mas_right).offset(10);
            make.height.equalTo(label.mas_height);
            make.width.equalTo(label.mas_width).multipliedBy(2);
        }];
        
        
        if (i == 0) {
            
            [self.keyWordButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(textField.centerY);
                make.left.equalTo(textField.mas_right).offset(10);
                make.height.equalTo(label.mas_height);
                make.width.equalTo(label.mas_width);
            }];
        }
        if (i == 3) {
            [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(textField.mas_bottom).offset(40);
                make.centerX.equalTo(textField.centerX);
                make.height.equalTo(textField.mas_height);
                make.width.equalTo(textField.mas_width);
            }];
        }
    }
}

#pragma mark - event response
- (void)cancleButtonEvent:(UIButton *)button {
    
    [self dismissViewControllerAnimated:YES completion:nil];

}

- (void)keyWordButtonEvent:(UIButton *)button {

    DDLogInfo(@"keyWordButtonEvent");
}

- (void)confirmButtonEvent:(UIButton *)button {
    DDLogInfo(@"confirmButtonEvent");

}
#pragma mark - getter
- (UILabel *)navLabel {
    if (!_navLabel) {
        _navLabel = [[UILabel alloc]init];
        _navLabel.text = @"找回密码";
        _navLabel.font = [UIFont systemFontOfSize:30];
        _navLabel.textAlignment = NSTextAlignmentCenter;
        _navLabel.userInteractionEnabled = YES;
        [self.view addSubview:_navLabel];
    }
    return _navLabel;
}

- (UIButton *)cancleButton {
    if (!_cancleButton) {
        _cancleButton = [UIButton btnWithTitle:@"取消"];
        [_cancleButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];        [_cancleButton addTarget:self action:@selector(cancleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self.navLabel addSubview:_cancleButton];
    }
    return _cancleButton;
}

- (UIButton *)keyWordButton {
    if (!_keyWordButton) {
        _keyWordButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _keyWordButton.layer.masksToBounds = YES;
        _keyWordButton.layer.cornerRadius = 5.0f;
        _keyWordButton.layer.borderWidth = 1;
        _keyWordButton.layer.borderColor = [UIColor grayColor].CGColor;
        [_keyWordButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_keyWordButton setTitle:@"获取验证码" forState:UIControlStateNormal];
        [_keyWordButton addTarget:self action:@selector(keyWordButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_keyWordButton];
    }
    return _keyWordButton;
}


- (UIButton *)confirmButton {
    if (!_confirmButton) {
        _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _confirmButton.backgroundColor = [UIColor colorWithRed:0.984 green:0.329 blue:0.306 alpha:1.000];
        _confirmButton.layer.masksToBounds = YES;
        _confirmButton.layer.cornerRadius = 5.0f;
        [_confirmButton setTitle:@"确    认" forState:UIControlStateNormal];
        _confirmButton.titleLabel.font = [UIFont systemFontOfSize:22];
        [_confirmButton addTarget:self action:@selector(confirmButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_confirmButton];
    }
    return _confirmButton;
}

@end
